#
# Makefile.in for UAE
#

@SET_MAKE@
CC        = @CC@
CPP       = @CPP@
CFLAGS    = @CFLAGS@ -D__inline__=@ac_cv_c_inline@ -DSTATFS_NO_ARGS=@STATFS_NO_ARGS@ -DSTATBUF_BAVAIL=@STATBUF_BAVAIL@ -DBROKEN_JOYSTICK_H=@BROKEN_JOYSTICK_H@ $(AFINCLUDE)
X_CFLAGS  = @X_CFLAGS@
TARGET    = @TARGET@
LIBRARIES = @LIBRARIES@ @LIBS@
GFXOBJS   = @GFXOBJS@
ASMOBJS   = @ASMOBJS@
CPUOBJS   = @CPUOBJS@
INSTALL         = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA    = @INSTALL_DATA@
prefix          = @prefix@
exec_prefix     = @exec_prefix@
bindir          = @bindir@
libdir          = @libdir@
sysconfdir      = @sysconfdir@

.SUFFIXES: .o .c .h .m

# If you want to use the AF System to play sound, set theese to the
# correct paths. If not, leave them commented out.
# (Don't forget to define AF_SOUND in config.h)
#AFINCLUDE=-I/usr/local/vol/AudioFile/include
#AFLDFLAGS=-L/usr/local/vol/AudioFile/lib -lAF

INCLUDES=-Iinclude

OBJS = main.o newcpu.o memory.o debug.o custom.o cia.o disk.o blitter.o $(GFXOBJS) \
       autoconf.o os.o ersatz.o filesys.o hardfile.o keybuf.o expansion.o zfile.o \
       fpp.o readcpu.o cpudefs.o gfxutil.o gfxlib.o blitfunc.o blittable.o $(ASMOBJS) \
       compiler.o serial.o uaelib.o execlib.o $(CPUOBJS) cpustbl.o
       
all: $(TARGET)

x11: progs

svgalib: progs

be: progs

next: progs
	cp uae ../Uae.app/Uae

progs: uae readdisk

install:

readdisk: readdisk.o
	$(CC) readdisk.o -o readdisk $(LDFLAGS) $(DEBUGFLAGS)

uae: $(OBJS)
	$(CC) $(OBJS) -o uae $(GFXLDFLAGS) $(AFLDFLAGS) $(LDFLAGS) $(DEBUGFLAGS) $(LIBRARIES) -lm

clean:
	-rm -f *.o uae readdisk
	-rm -f gencpu genblitter build68k cpudefs.c cpuopti
	-rm -f cpu?.c blit.h
	-rm -f cputbl.h cpustbl.c cpu_fast?.s
	-rm -f blitfunc.c blitfunc.h blittable.c config.h

halfclean:
	-rm -f $(OBJS) $(GFXOBJS)

streifenfrei: clean
	-rm -f Makefile config.cache config.log config.status include/sysconfig.h

blit.h: genblitter
	./genblitter i >blit.h
blitfunc.c: genblitter blitfunc.h
	./genblitter f >blitfunc.c
blitfunc.h: genblitter
	./genblitter h >blitfunc.h
blittable.c: genblitter blitfunc.h
	./genblitter t >blittable.c

genblitter: genblitter.o
	$(CC) $(LDFLAGS) -o genblitter genblitter.o
build68k: build68k.o
	$(CC) $(LDFLAGS) -o build68k build68k.o
cpuopti: cpuopti.o
	$(CC) $(LDFLAGS) -o cpuopti cpuopti.o
gencpu: gencpu.o readcpu.o cpudefs.o
	$(CC) $(LDFLAGS) -o gencpu gencpu.o readcpu.o cpudefs.o

custom.o: blit.h

cpudefs.c: build68k table68k
	./build68k >cpudefs.c
cpustbl.c: gencpu
	./gencpu s >cpustbl.c
cputbl.c: gencpu
	./gencpu t >cputbl.c
cputbl.h: gencpu
	./gencpu h >cputbl.h

cpu0.c: gencpu
	./gencpu f 0 >cpu0.c
cpu1.c: gencpu
	./gencpu f 1 >cpu1.c
cpu2.c: gencpu
	./gencpu f 2 >cpu2.c
cpu3.c: gencpu
	./gencpu f 3 >cpu3.c
cpu4.c: gencpu
	./gencpu f 4 >cpu4.c
cpu5.c: gencpu
	./gencpu f 5 >cpu5.c
cpu6.c: gencpu
	./gencpu f 6 >cpu6.c
cpu7.c: gencpu
	./gencpu f 7 >cpu7.c
cpu8.c: gencpu
	./gencpu f 8 >cpu8.c
cpu9.c: gencpu
	./gencpu f 9 >cpu9.c
cpuA.c: gencpu
	./gencpu f 10 >cpuA.c
cpuB.c: gencpu
	./gencpu f 11 >cpuB.c
cpuC.c: gencpu
	./gencpu f 12 >cpuC.c
cpuD.c: gencpu
	./gencpu f 13 >cpuD.c
cpuE.c: gencpu
	./gencpu f 14 >cpuE.c
cpuF.c: gencpu
	./gencpu f 15 >cpuF.c

cpu0.o: cpu0.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpu1.o: cpu1.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpu2.o: cpu2.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpu3.o: cpu3.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpu4.o: cpu4.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpu5.o: cpu5.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpu6.o: cpu6.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpu7.o: cpu7.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpu8.o: cpu8.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpu9.o: cpu9.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpuA.o: cpuA.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpuB.o: cpuB.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpuC.o: cpuC.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpuD.o: cpuD.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpuE.o: cpuE.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
cpuF.o: cpuF.c cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
       
cpu_fast0.o: cpu_fast0.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fast1.o: cpu_fast1.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fast2.o: cpu_fast2.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fast3.o: cpu_fast3.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fast4.o: cpu_fast4.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fast5.o: cpu_fast5.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fast6.o: cpu_fast6.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fast7.o: cpu_fast7.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fast8.o: cpu_fast8.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fast9.o: cpu_fast9.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fastA.o: cpu_fastA.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fastB.o: cpu_fastB.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fastC.o: cpu_fastC.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fastD.o: cpu_fastD.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fastE.o: cpu_fastE.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s
cpu_fastF.o: cpu_fastF.s cputbl.h
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.s

cpu_fast0.s: cpu0.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fast1.s: cpu1.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fast2.s: cpu2.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fast3.s: cpu3.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fast4.s: cpu4.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fast5.s: cpu5.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fast6.s: cpu6.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fast7.s: cpu7.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fast8.s: cpu8.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fast9.s: cpu9.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fastA.s: cpuA.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fastB.s: cpuB.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fastC.s: cpuC.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fastD.s: cpuD.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fastE.s: cpuE.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s
cpu_fastF.s: cpuF.c cputbl.h cpuopti
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $< -o cpu-tmp.s
	cpuopti <cpu-tmp.s >$@
	rm cpu-tmp.s

bebox.o: bebox.cpp
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) bebox.cpp

.m.o:
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $*.m
.c.o:
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $*.c
.c.s:
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $*.c
.S.o:
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $*.S

# Saves recompiling...
touch:
	touch *.o; touch build68k; touch cpudefs.c; touch cpudefs.o; touch gencpu genblitter; touch cpu?.c cpu*tbl.[ch]; touch cpu?.o cpu*tbl.o

# Some more dependencies...
cpustbl.o: cputbl.h
cputbl.o: cputbl.h

build68k.o: include/readcpu.h
readcpu.o: include/readcpu.h

main.o: config.h
cia.o: config.h include/events.h
custom.o: config.h include/events.h
newcpu.o: config.h include/events.h
autoconf.o: config.h
expansion.o: config.h
xwin.o: config.h
svga.o: config.h
bebox.o: config.h
os.o: config.h
memory.o: config.h
debug.o: config.h
fpp.o: config.h
ersatz.o: config.h
filesys.o: config.h
execlib.o: config.h
disk.o: config.h include/events.h
blitter.o: config.h include/events.h

config.h: ../config.h
	ln -s ../config.h config.h

